Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(logger): log event functionality #1004

Merged
merged 11 commits into from
Jun 23, 2022
Merged

Feat(logger): log event functionality #1004

merged 11 commits into from
Jun 23, 2022

Conversation

saragerion
Copy link
Contributor

@saragerion saragerion commented Jun 22, 2022

Description of your changes

This PR introduces a new functionality: logging Lambda events. Developers can opt in for this behaviour by one of the following methods:

  • passing the parameter logEvent set to true to the injectLambdaContext middleware
  • passing the parameter logEvent set to true to the injectLambdaContext decorator
  • setting the env var POWERTOOLS_LOGGER_LOG_EVENT to through while using the injectLambdaContext middleware/decorator

Note that this functionality is only available when using a middleware or decorator.

The Lambda invocation will then print one log item with the following key-value pairs:

  • logLevel INFO
  • message key with value Lambda invocation event
  • event key with the current Lambda invocation event as value

Logging a Lambda event is very typical use of a logger in AWS Lambda. This logic aims to simplify and reduce the code that developers need to maintain.

How to verify this change

See E2E tests results.

To see the docs:

npm run docs-website-build-run

carbon (4)

Related issues, RFCs

#482

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published in downstream module
  • The PR title follows the conventional commit semantics

Breaking change checklist

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 22, 2022

📊 Package size report   1%↑

File Before After
aws-lambda-powertools-logger-0.10.0.tgz 22.9 kB 4%↑23.7 kB
logger-bundle.zip 23.4 kB 3%↑24.2 kB
Total (Includes all files) 138.6 kB 1%↑140.2 kB
Tarball size 137.4 kB 1%↑139.0 kB
Unchanged files
File Size
aws-lambda-powertools-commons-0.10.0.tgz 6.5 kB
aws-lambda-powertools-metrics-0.10.0.tgz 17.5 kB
aws-lambda-powertools-tracer-0.10.0.tgz 21.4 kB
commons-bundle.zip 7.0 kB
metrics-bundle.zip 18.0 kB
tracer-bundle.zip 21.9 kB

🤖 This report was automatically generated by pkg-size-action
(options hash: e084ed7e8abaceaf318cc37424bd7f7a)

@saragerion saragerion added this to the production-ready-release milestone Jun 23, 2022
@saragerion saragerion self-assigned this Jun 23, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2022

📊 Package size report   1%↑

File Before After
aws-lambda-powertools-logger-0.10.0.tgz 22.9 kB 4%↑23.7 kB
logger-bundle.zip 23.4 kB 3%↑24.2 kB
Total (Includes all files) 138.6 kB 1%↑140.2 kB
Tarball size 137.4 kB 1%↑139.0 kB
Unchanged files
File Size
aws-lambda-powertools-commons-0.10.0.tgz 6.5 kB
aws-lambda-powertools-metrics-0.10.0.tgz 17.5 kB
aws-lambda-powertools-tracer-0.10.0.tgz 21.4 kB
commons-bundle.zip 7.0 kB
metrics-bundle.zip 18.0 kB
tracer-bundle.zip 21.9 kB

🤖 This report was automatically generated by pkg-size-action
(options hash: 7baa0109941e106e7ebfcd7771808605)

@saragerion saragerion linked an issue Jun 23, 2022 that may be closed by this pull request
8 tasks
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2022

📊 Package size report   1%↑

File Before After
aws-lambda-powertools-logger-0.10.0.tgz 22.9 kB 4%↑23.7 kB
logger-bundle.zip 23.4 kB 3%↑24.2 kB
Total (Includes all files) 138.6 kB 1%↑140.2 kB
Tarball size 137.4 kB 1%↑139.0 kB
Unchanged files
File Size
aws-lambda-powertools-commons-0.10.0.tgz 6.5 kB
aws-lambda-powertools-metrics-0.10.0.tgz 17.5 kB
aws-lambda-powertools-tracer-0.10.0.tgz 21.4 kB
commons-bundle.zip 7.0 kB
metrics-bundle.zip 18.0 kB
tracer-bundle.zip 21.9 kB

🤖 This report was automatically generated by pkg-size-action
(options hash: 5c696c1703417abbb857a9081c753d78)

@saragerion saragerion marked this pull request as ready for review June 23, 2022 12:51
@saragerion saragerion requested review from dreamorosi and flochaz June 23, 2022 12:53
Copy link
Contributor

@flochaz flochaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

You can build and start a local docs website by running these two commands:
You can build and start a local docs website by running:

`npm run docs-website-build-run`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be cool in the future (not this PR) to have an additional combo command to run the docs & the API docs at the same time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant something like (name is just an example):

"docs-run-docs-and-api": "npm run docs-runLocalDocker && npm run docs-api-build-run"

This command would allow you to run the documentation + the API docs so you can browse between both. Right now when editing locally, if you start from the docs and click on "API Docs" on the left navigation menu it gives you a 404 because there's nothing on the /api path.

But again, we can do it at some point in the future!

@saragerion
Copy link
Contributor Author

E2E tests:
https://github.com/awslabs/aws-lambda-powertools-typescript/actions/runs/2549417761

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, looking forward to merge it!

A couple of minor notes, which I will capture in a separate issue for later:

  • I'd like to see a corresponding method for manual mode like logger.logEvent(event); - this is purely syntactic sugar as you can easily do logger.debug('event', { event }); but still.
  • Since in the docs we call out that this method is for debugging only, I'd expect the log level to be DEBUG instead of INFO.
  • In the packages/logger/src/middy.ts docstring of the injectLambdaContext middleware we should document the new flag/new behaviour so that it appears also in the API docs.
  • In the new sub-section of the docs where we show this method, it'd be nice to have a log excerpt. I was not sure which key the event would use in the JSON log (event duh).

@saragerion saragerion merged commit 9a976ca into main Jun 23, 2022
@saragerion saragerion deleted the feat/logger-log-event branch June 23, 2022 14:12
dreamorosi pushed a commit that referenced this pull request Aug 2, 2022
* feat(logger): log event, add business logic and unit tests

* test(logger): add log event support

* feat(logger): add env variable for log event

* test(logger): middy

* chore(logger): middy polish for log event

* test(logger): fix log event unit tests

* test(logger): unit + e2e tests for log event functionality

* docs(logger): add log event

* docs: add single line command for docs generation

* docs: fix typo in env vars section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: feature parity with Python Powertools logger
3 participants